Skip to content

[ResponseOps][Alerting v2] Move episodes time filter inside query, include previous actions - #290452

Open
umbopepato wants to merge 5 commits into
elastic:mainfrom
umbopepato:1030-episodes-query-time-filter-ignores-previous-actions
Open

[ResponseOps][Alerting v2] Move episodes time filter inside query, include previous actions#290452
umbopepato wants to merge 5 commits into
elastic:mainfrom
umbopepato:1030-episodes-query-time-filter-ignores-previous-actions

Conversation

@umbopepato

@umbopepato umbopepato commented Sep 11, 2026

Copy link
Copy Markdown
Member

📄 Summary

Important

Alerting v2 work under feature flag disabled by default. See 🧪 Verification steps > ⚙️ Environment Setup for more information.

  • Applies the time picker range to the alert events only. Until now the range filtered every document before the aggregations ran, so an episode lost its actions-derived metadata (tags, ack, assignee and snooze) if those actions were outside the time range, and its duration only covered the part inside the range.
  • Marks the duration with a gte symbol (≥ 14 min, with a tooltip) when the episode started before the range, since first_timestamp cannot be outside the range. The flyout still shows the full value.
    ⚠️ This is a compromise solution to keep the query performant. All other solutions that queried unbounded rule-events to look for the episode start event were painfully slow (~1min load time on a local setup with around 70 episodes across 1 day of activity). More in 🧰 Implementation details

🧪 Verification steps

⚙️ Environment Setup

Add the following flag to your kibana.dev.yml:

xpack.alerting_v2.enabled: true

Then navigate to Stack Management > Advanced settings > Global, and enable Alerting v2

You need an episode that has been active for a while (i.e. more than an hour), with a tag and an ack added shortly after it started.

✅ Happy Path

  1. Open the episodes list with Last 15 minutes selected
  2. The episode row shows its tags and the ack indicator
  3. The duration cell shows followed by the duration seen inside the range, and hovering it explains why
  4. Widen the range to include the episode start: the goes away and the duration becomes the full one

⚡️ Edge Cases

  1. Open the flyout of a row: it shows the full duration and the same tags and ack
  2. The acknowledged and snoozed KPIs count the episode on the short range too
  3. Filtering by one of its tags still returns the episode on the short range

🐞 Known issues & potential improvements

  • The duration is still clamped to the range, but at least it's flagged with a symbol and explanation in the cell. To make it exact at the same cost some work on the data itself is necessary. I.E. have the director write the episode start on each event.
  • Rules with pending_count: 0 skip the pending state, so when no earlier episode of the same series is in range we can't tell whether we saw the start, and the row shows even when the duration is exact.
  • The $.alert-episodes view has the same aggregation shape and Discover pushes its own range down, so the profile is not covered by this change.

🧰 Implementation details

The range is sent as a request filter (bool.should: [type == "alert" AND range, exists(action_type)]) through input.filters instead of the esql function's timeField, so ES still bounds the .rule-events scan at the Lucene level and every .alert-actions doc passes. Measured on 2M events at 12h: 0.18s vs 0.11s before.

I first tried selecting the episodes in range with an IN (subquery) and aggregating their full history (@adcoelho's suggestion), to fix the duration too. ES does not push the subquery down: 28s on the same data. A literal id list is pushed down (0.3s), but that means two requests.

📷 Screenshots

image

⏪ Backport rationale

Alerting v2 pre-GA work, not backporting

🔗 References

Fixes https://github.com/elastic/rna-program/issues/1030

🤖 PR Co-authored by Claude Code

☑️ Checklist

@umbopepato umbopepato added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// Feature:AlertingV2 v9.6.0 labels Sep 11, 2026
@infra-vault-gh-plugin-prod

infra-vault-gh-plugin-prod Bot commented Sep 11, 2026

Copy link
Copy Markdown
🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!
  • Click to trigger kibana-deploy-cloud-from-pr for this PR!
  • Click to trigger kibana-entity-store-performance-from-pr for this PR!
  • Click to trigger kibana-storybooks-from-pr for this PR!

@umbopepato
umbopepato marked this pull request as ready for review September 11, 2026 10:32
@umbopepato
umbopepato requested a review from a team as a code owner September 11, 2026 10:32
@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

Pinging @elastic/response-ops (Team:ResponseOps)

@kibanamachine

kibanamachine commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

💔 Build Failed

Failed CI Steps

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
alertingVTwo 864.9KB 868.1KB +3.1KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
shared-packages 4.6MB 4.6MB +60.0B
Unknown metric groups

total optimizer output size

id before after diff
all 63.9MB 63.9MB +3.2KB

History

bool: {
should: [
{ bool: { filter: [{ term: { type: 'alert' } }, rangeFilter.query] } },
{ exists: { field: 'action_type' } },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, the action is unbounded on both sides, not only before the range. Thats the idea?
For a historical window (e.g. yesterday 14:00–15:00), we see the current status(action whatever) and not the status at the time 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I don't know what's the best approach here to be honest... Showing older action info, while the user might expect to see the latest state? The reverse? Or even exclude episodes don't have rule-events anymore now, even if they had them in the time window? I'm leaning towards the more up to date info.

For sure the current status is currently not visible since we take that from the last rule-event we see in the interval, so if the user manually resolved an active alert, it still shows as active in an older time window. We could enqueue an improvement on this, and maybe show a separate indication for "in this time range" vs "now"

query,
input,
abortSignal,
timeField: DEFAULT_TIME_FIELD,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag options still go through timeField + input.timeRange, so the dropdown only sees tag actions inside the picker range.

After this change, the list row can show a tag whose action is before the range, but won't that value be missing from the combo box?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right, I missed this one. Fixed!

@adcoelho adcoelho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please double check this one? Otherwise looks good to me and i can approve once the pipeline passes 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:AlertingV2 release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v9.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants